from django.db import models
from django.contrib.auth.models import User
from django_facebook.models import FacebookProfileModel

class Department(models.Model):
  short_name = models.CharField(max_length=15, unique=True)
  long_name = models.CharField(max_length=50)
  
class Course(models.Model):
  dept = models.ForeignKey(Department)
  # Course Number
  number = models.CharField(max_length=10)
  # Course Name
  long_name = models.CharField(max_length=50)
  # Unique Name
  def _fill_short_name(self):
    return '%s %s' % (self.dept.short_name, self.number)
  short_name = models.CharField(max_length=15, unique=True)
  def __str__(self):
    return '%s %s' % (self.dept.short_name, self.number)
  
class Assignment(models.Model):
  # Assignment name
  name = models.CharField(max_length=50)
  # Course it relates to
  course = models.ForeignKey(Course)
  # Due date
  due = models.DateField()
  # Description
  description = models.CharField(max_length=100, blank=True)
  # Added by...
  added_by = models.ForeignKey(User)
  
class UserProfile(FacebookProfileModel):
  # This field is required.
  user = models.OneToOneField(User)
  # List of courses this person is taking
  courses = models.ManyToManyField(Course, blank=True)
  # List of assignments
  assignments = models.ManyToManyField(Assignment, through='UserAssignment')
  
class UserAssignment(models.Model):
  user_profile = models.ForeignKey(UserProfile)
  assignment = models.ForeignKey(Assignment)
  # Finished or not
  done = models.BooleanField(default=False)
  hide = models.BooleanField(default=False)